<template>
  <page-header-wrapper>
    <a-table :columns="columns" :data-source="listData" :loading="loading">
      <span slot="action" slot-scope="text, record">
        <template>
          <a v-if="record.deleted === 0" @click="close(record)">取消开通</a>
          <a v-else @click="pass(record)">开通</a>
          <a-divider type="vertical" />
        </template>
      </span>
    </a-table>
  </page-header-wrapper>
</template>

<script>
import storage from 'store'

export default {
  name: 'TableList',
  // components: {
  //   STable
  // },
  data () {
    return {
      loading: false,
      pagesize: 20,
      searchText: '',
      listData: [],
      // 表头
      columns: [
        {
          title: '学校名称',
          dataIndex: 'schoolName'
        },
        {
          title: '姓名',
          dataIndex: 'personName'
        },
        {
          title: '手机号',
          dataIndex: 'phone'
        },
        {
          title: '申请时间',
          dataIndex: 'createTime'
        },
        {
          title: '审批',
          dataIndex: 'action',
          width: '250px',
          scopedSlots: { customRender: 'action' }
        }
      ]
    }
  },
  created () {
    if (!storage.get('schoolID')) {
      this.$store.dispatch('Logout').then(() => {
        this.$router.push({ name: 'login' })
        this.$router.go(0)
      })
    }
    this.getList()
  },
  methods: {
    getList () {
      this.loading = true
      const param = {
      }
      if (storage.get('schoolID')) {
        param.schoolID = storage.get('schoolID')
      }
      this.fetchList('/carrierSchool/manage', param).then(res => {
        this.listData = res.data
        this.loading = false
      })
    },
    pass (item) {
      item = {
        schoolID: item.schoolID,
        carrierID: item.carrierID
      }
      this.loading = true
      this.fetchList('/carrierSchool/pass', item).then(data => {
        this.getList()
      })
    },
    close (item) {
      item = {
        schoolID: item.schoolID,
        carrierID: item.carrierID
      }
      this.loading = true
      this.fetchList('/carrierSchool/close', item).then(data => {
        this.getList()
      })
    }
  }
}
</script>
